import 'package:flutter/material.dart';
import 'mydata.dart'; // 修改导入路径

class LoginPage extends StatelessWidget {
  final TextEditingController _usernameController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('登录'),
        backgroundColor: Colors.purple, // 设置AppBar背景颜色为紫色
        centerTitle: true, // 让标题居中
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextField(
                controller: _usernameController,
                decoration: InputDecoration(
                  labelText: '用户名',
                  border: OutlineInputBorder(),
                  filled: true,
                  fillColor: Colors.purple[50], // 设置输入框背景颜色为浅紫色
                ),
              ),
              SizedBox(height: 16.0),
              TextField(
                controller: _passwordController,
                obscureText: true,
                decoration: InputDecoration(
                  labelText: '密码',
                  border: OutlineInputBorder(),
                  filled: true,
                  fillColor: Colors.purple[50], // 设置输入框背景颜色为浅紫色
                ),
              ),
              SizedBox(height: 24.0),
              ElevatedButton(
                onPressed: () {
                  // 登录逻辑
                  if (_usernameController.text == '' && _passwordController.text == '') {
                    Navigator.pushReplacement(
                      context,
                      MaterialPageRoute(builder: (context) => HomePage()),
                    );
                  } else {
                    // 显示错误信息
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text('用户名或密码错误')),
                    );
                  }
                },
                style: ElevatedButton.styleFrom(
                  foregroundColor: Colors.white,
                  backgroundColor: Colors.purple, // 设置按钮文字颜色为白色
                ),
                child: Text('登录'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}